{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "709053b1",
   "metadata": {},
   "source": [
    "------------\n",
    "* 2022/10/13/week 08\n",
    "* Python学习记录\n",
    "* 记录人：wu-huichun\n",
    "-----------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3bee3cdf",
   "metadata": {},
   "source": [
    "# 1.数字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "03f79c56",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "28\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "wait_time = random.randint(1, 60)\n",
    "print(wait_time)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7edd1554",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 + 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ddc75821",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "20"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "50 - 5*6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8cb13211",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5.0"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(50 - 5*6) / 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "bd6fcef2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.6"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "8 / 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "b412799b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5.666666666666667"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17 / 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "d37c65a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17 // 3  # 取整数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "103d6a56",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17 % 3  # 余数为2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "1f26029d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "5 ** 2  # 5的平方"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "f8f439c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "900"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "width = 20\n",
    "height = 5 * 9\n",
    "width * height"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "1218059b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14.0"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "4 * 3.75 - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "849e5414",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12.5625"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tax = 12.5 / 100\n",
    "price = 100.50\n",
    "price * tax"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "be2dae38",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "113.0625"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "price + _"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "7e95435c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "113.06"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "round(_, 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dc4812bc",
   "metadata": {},
   "source": [
    "# 2.字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "bae0db9d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'spam eggs'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'spam eggs'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "c2b74643",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'doesn\\'t'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "61d45acb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "1429ab78",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\"Yes,\" they said.'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\"Yes,\" they said.'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "0e98f2ac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\"Yes,\"they said.'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\\\"Yes,\\\"they said.\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "6f23ea1d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\"Isn\\'t,\" they said.'"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\"Isn\\'t,\" they said.'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "51bb9cb1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\"Isn\\'t,\" they said.'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\"Isn\\'t,\" they said.'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "f4e2c948",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\"Isn't,\" they said.\n"
     ]
    }
   ],
   "source": [
    "print('\"Isn\\'t,\" they said.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "e64d30c9",
   "metadata": {},
   "outputs": [],
   "source": [
    "s = 'First line.\\nSecond line.'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "1721e95c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'First line.\\nSecond line.'"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "855f4a87",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "First line.\n",
      "Second line.\n"
     ]
    }
   ],
   "source": [
    "print(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "7ba803cb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "C:\\some\n",
      "ame\n"
     ]
    }
   ],
   "source": [
    "print('C:\\some\\name') # \\n 表示换行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "21973123",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "C:\\some\\name\n"
     ]
    }
   ],
   "source": [
    "print(r'C:\\some\\name')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "f805af25",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Usage: thingy [OPTIONS]\n",
      "    -h\n",
      "    -H hostname\n",
      "    \n"
     ]
    }
   ],
   "source": [
    "print(\"\"\"\\\n",
    "Usage: thingy [OPTIONS]\n",
    "    -h\n",
    "    -H hostname\n",
    "    \"\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "7fe12b55",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'unununium'"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 * 'un' + 'ium'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "77bd46d2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Python'"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Py' 'thon'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "084c26d9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'tho'"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "word = 'Python'\n",
    "word[0]\n",
    "word[4]\n",
    "word[-1]\n",
    "word[-2]\n",
    "word[0:2]\n",
    "word[2:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "281b3843",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Python'"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "word[:2] + word[2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "4f442c7b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'onPyth'"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "word[4:] + word[:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "0d5f338d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Jython'"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'J' + word[1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "f46ff5ef",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Pypy'"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "word[:2] + 'py'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "0fc59dbe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "34"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = 'supercalifragilisticexpialidocious'\n",
    "len(s)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d2571a70",
   "metadata": {},
   "source": [
    "# 3. 列表（中括号）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "31e72a53",
   "metadata": {},
   "source": [
    "> 1.列表：有序的可变对象集合（可变的）\n",
    "\n",
    "> 2.按字面创建列表 "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8daaa121",
   "metadata": {},
   "source": [
    "> 3.使用列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "afc110c0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a', 'e', 'i', 'o', 'u']\n",
    "word = \"Milliways\"\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "162c0bd5",
   "metadata": {},
   "source": [
    "> 4.在运行时“扩展”列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "5c5ee484",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "found = []\n",
    "len(found)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "e55eb200",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "found.append('a')\n",
    "len(found)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "3a35251c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a']"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "found"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "566825a7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'e', 'i', 'o']"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "found.append('e')\n",
    "found.append('i')\n",
    "found.append('o')\n",
    "len(found)\n",
    "found"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bd9e123d",
   "metadata": {},
   "source": [
    "> 5.用 \"in\" \"not in\" 检查成员关系"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "33b94c0e",
   "metadata": {},
   "source": [
    "> 6.更新代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9badf0e8",
   "metadata": {},
   "outputs": [],
   "source": [
    "vowels = ['a', 'e', 'i', 'o', 'u']\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.affend(letter)\n",
    "for vowel in found:\n",
    "        print(vowel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "61f7e6bb",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
